<?php

namespace app\admin\model;
use think\Model;
use fast\Tree;

class Article extends Model
{
    // 表名
    public $name = 'article';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    public $data;


    public function getCityidTextAttr($value, $data)
    {
        $nn=preg_split("/,/",$value);
        $s=array();
        for($i=0;$i<count($nn);$i++) {
            if($nn[$i]=="") continue;
            $r = Model("cityarea")->get(array("id" => $nn[$i]));
            if($r) $s[]= $r['name'];
        }
        return join(",",$s);
    }

    protected function setCityidAttr($value)
    {
        return $value&&is_array($value)?join(",",$value):$value;
    }

    public function getSchoolidTextAttr($value, $data)
    {
        $nn=preg_split("/,/",$value);
        $s=array();
        for($i=0;$i<count($nn);$i++) {
            if($nn[$i]=="") continue;
            $r = Model("school")->get(array("id" => $nn[$i]));
            if($r) $s[]= $r['name'];
        }
        return join(",",$s);
    }

    protected function setSchoolidAttr($value)
    {
        return $value&&is_array($value)?join(",",$value):$value;
    }

}